package com.ningxia.water.reuslt;

import com.alibaba.fastjson.JSONObject;
import com.ningxia.water.exception.BaseErrorInfoInterface;
import lombok.Data;

/**
 * 统一API响应结果封装
 * @author hz
 * @since 2021-03-15
 */

@Data
public class Result<T> {

    /**
     * 响应代码
     */
    private String code;

    /**
     * 响应消息
     */
    private String message;

    /**
     * 响应结果
     */
    private T data;

    public Result() {
    }

    public Result(BaseErrorInfoInterface errorInfo) {
        this.code = errorInfo.getResultCode();
        this.message = errorInfo.getResultMsg();
    }


    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }

}
